package com.anxin.converter;

import com.anxin.entity.DoctorInfo;
import com.anxin.entity.excel.DoctorInfoExcel;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.stream.Collectors;

@Component
public class DoctorInfoConverter {
    
    public DoctorInfoExcel toExcel(DoctorInfo doctorInfo) {
        if (doctorInfo == null) {
            return null;
        }
        
        DoctorInfoExcel excel = new DoctorInfoExcel();
        excel.setId(doctorInfo.getId());
        excel.setUserId(doctorInfo.getUserId());
        excel.setDepartmentId(doctorInfo.getDepartmentId());
        excel.setTitle(doctorInfo.getTitle());
        excel.setSpecialty(doctorInfo.getSpecialty());
        excel.setIntroduction(doctorInfo.getIntroduction());
        excel.setEducation(doctorInfo.getEducation());
        excel.setWorkYears(doctorInfo.getWorkYears());
        excel.setStatus(doctorInfo.getStatus() == 1 ? "正常" : "停用");
        
        return excel;
    }
    
    public DoctorInfo toEntity(DoctorInfoExcel excel) {
        if (excel == null) {
            return null;
        }
        
        DoctorInfo doctorInfo = new DoctorInfo();
        doctorInfo.setId(excel.getId());
        doctorInfo.setUserId(excel.getUserId());
        doctorInfo.setDepartmentId(excel.getDepartmentId());
        doctorInfo.setTitle(excel.getTitle());
        doctorInfo.setSpecialty(excel.getSpecialty());
        doctorInfo.setIntroduction(excel.getIntroduction());
        doctorInfo.setEducation(excel.getEducation());
        doctorInfo.setWorkYears(excel.getWorkYears());
        doctorInfo.setStatus("正常".equals(excel.getStatus()) ? 1 : 0);
        
        return doctorInfo;
    }
    
    public List<DoctorInfoExcel> toExcelList(List<DoctorInfo> doctorInfoList) {
        return doctorInfoList.stream()
                .map(this::toExcel)
                .collect(Collectors.toList());
    }
    
    public List<DoctorInfo> toEntityList(List<DoctorInfoExcel> excelList) {
        return excelList.stream()
                .map(this::toEntity)
                .collect(Collectors.toList());
    }
} 